#!/usr/bin/perl -w

use strict;
use warnings;

use FindBin '$Bin';
use lib "$Bin/../lib";

#it's still in a branch....
use lib '/home/groditi/devel/reaction/Reaction/0.001/branches/code_generation/lib';

use Reaction::InterfaceModel::Reflector::DBIC;
use aliased 'Cantella::DJabberd::Web::InterfaceModel::Action::User::Login';
use aliased 'Cantella::DJabberd::Web::InterfaceModel::Action::User::Create';

my $reflector = Reaction::InterfaceModel::Reflector::DBIC->new
  ( object_actions =>
    {
     Login => {attributes => [], name => 'Login', base => Login},
    },
  );

$reflector->reflect_schema
  (
   model_class  => 'Cantella::DJabberd::Web::AdminModel',
   schema_class => 'Cantella::DJabberd::Schema',
   domain_model_name => 'djabberd_schema',
   sources =>
   [
    [ ExternalComponent => { reader => "external_components" }, ],
    [ JabberGroup       => { reader => "jabber_groups"       }, ],
    [ RosterGroup       => { reader => "roster_groups"       }, ],
    [ RosterItem        => { reader => "roster_items"        }, ],
    [ Vhost             => { reader => "vhosts"              }, ],
    [ VhostBridge       => { reader => "vhost_bridges"       }, ],
    [ LoggedMessage =>
      {
       reader => "logged_messages",
       actions    => [],
       collection => { actions => [] },
      },
    ],
    [ LoggedConversation =>
      {
       reader     => "logged_conversations",
       actions    => [],
       collection => { actions => [] },
      }
    ],
     [ User =>
       { reader => "users",
         domain_model_args => { handles => [ qw/check_password/ ] },
         collection =>
         { actions => [ Create => { base => Create, attributes => [] } ], },
         actions =>
         [ qw/Login/,
           [ Update => { attributes => [qw/username full_name/] } ],
         ],
       },
     ],
     [ UserJid =>
       { reader => "user_jids",
        collection =>
         { actions =>
           [ Create => { attributes => [qw/jid user jabber_groups/] } ],
         },
         actions =>
         [ qw/Delete/,
           [ Update => { attributes => [qw/jid user jabber_groups/] } ],
         ],
       }
     ],
   ],
  );

$reflector->write_code_for_all_classes("$Bin/../lib");

1;
